import * as type from './mutation-types'
import {
  setCache,
  clearCache,
  keys
} from '../_util'

export default {
  [type.BIND_USER] (state, info) {
    state.user = info
    setCache(keys.user, info)
  },
  [type.UNBIND_ALL] (state) {
    state.user = null
    clearCache()
  },
  [type.BIND_LOADING] (state, menus) {
    state.loading = menus
  },
  [type.BIND_VIEWACTION] (state, path) {
    state.viewAction = path
  },
  [type.BIND_UPLOADACTION] (state, path) {
    state.uploadAction = path
  },
  [type.BIND_TOKEN] (state, token) {
    state.token = token
  },
  [type.BIND_DEVID] (state, devid) {
    state.devid = devid
    setCache(keys.devid, devid)
  },
  [type.BIND_VERSION] (state, version) {
    state.version = version
    setCache(keys.version, version)
  },
  [type.BIND_WXINITSTEP] (state, wxInitStep) {
    state.wxInitStep = wxInitStep
    setCache(keys.wxInitStep, wxInitStep)
  }
}
